<template>
  <div class="main-menu">
    <div class="logo">
      <img src="@/assets/img/logo.svg" alt="" class="img" />
      <h2 class="title" v-show="!isFold">后台管理系统</h2>
    </div>
    <!-- 菜单 -->
    <div class="menu">
      <el-menu
        :default-active="defaultActive"
        text-color="#b7bdc3"
        active-text-color="#fff"
        background-color="#001529"
        :collapse="isFold"
      >
        <!-- 系统总览 -->
        <template v-for="item in userMenus" :key="item.id">
          <el-sub-menu :index="item.id + ''">
            <template #title>
              <!-- <component :is="item.icon.split('-icon-')[1]" /> -->
              <el-icon>
                <!-- <location /> -->
                <component :is="item.icon.split('-icon-')[1]" />
              </el-icon>
              <span>{{ item.name }}</span>
            </template>
            <template v-for="subItems in item.children" :key="subItems.id">
              <el-menu-item
                :index="subItems.id + ''"
                @click="handleItemClick(subItems)"
                >{{ subItems.name }}
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
        <!-- 系统管理 -->
        <!-- url:/main/analysis/overview -->
        <!-- /main/system -->
        <!--/main/product -->
        <!-- /main/story -->
        <!-- 商品中心 -->
        <!-- 随便聊聊 -->
      </el-menu>
    </div>
  </div>
</template>

<script setup lang="ts">
import useLoginStroe from "@/stores/login/login"
import { computed, ref } from "vue"
import { useRoute, useRouter } from "vue-router"
import { fristMenu,mapPathToMenu } from "@/utils/map-menus"
const loginStroe = useLoginStroe()
const router = useRouter()
const userMenus = loginStroe.userMenus
defineProps({
  isFold: {
    type: Boolean,
    default: false
  }
})
// 路由跳转
function handleItemClick(item: any) {
  // console.log(item.url)
  router.push(item.url)
}
// elmenu的默认菜单
const route=useRoute()
const  defaultActive=computed(()=>{
  const pathMenu=mapPathToMenu(route.path,userMenus)
  return pathMenu.id + ""
})


</script>
<style lang="less" scoped>
.main-menu {
  height: 100%;
  background-color: #001529;
}

.logo {
  display: flex;
  height: 28px;
  padding: 12px 10px 8px 10px;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;

  .img {
    height: 100%;
    margin: 0 10px;
  }

  .title {
    font-size: 16px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
  }
}

.el-menu {
  border-right: none;
  user-select: none;
}

.el-sub-menu {
  .el-menu-item {
    padding-left: 50px !important;
    background-color: #0c2135;
  }

  .el-menu-item:hover {
    color: #fff;
  }

  .el-menu-item.is-active {
    background-color: #0a60bd;
  }
}
</style>
